﻿using System;
using System.Web;
using System.Web.Caching;

namespace LsTool
{
    /// <summary>
    /// 缓存
    /// </summary>
    public class CaCheCom
    {
        /// <summary>
        /// 添加缓存(绝对过期)
        /// </summary>
        /// <param name="key"></param>
        /// <param name="val"></param>
        /// <param name="dateTime"></param>
 
        public static void AddCaChe(string key, object val, DateTime dateTime)
        {
            HttpRuntime.Cache.Insert(key, val, null, dateTime, Cache.NoSlidingExpiration);
        }

        /// <summary>
        /// 获取缓存
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public static object GetCaChe(string key)
        {
            return HttpRuntime.Cache[key];
        } 
        
        /// <summary>
        /// 获取缓存
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public static object DelCaChe(string key)
        {
            return HttpRuntime.Cache.Remove(key);
        }


        /// <summary>
        /// 添加缓存(相对过期)
        /// </summary>
        /// <param name="key"></param>
        /// <param name="val"></param>
        /// <param name="timeSpan"></param>
        public static void AddCaChe(string key, object val, TimeSpan timeSpan)
        {
            HttpRuntime.Cache.Insert(key, val, null, Cache.NoAbsoluteExpiration, timeSpan);
        }


    }
}